package com.xinghe.sharedevice.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.xinghe.sharedevice.domain.Station;
import com.xinghe.sharedevice.service.IStationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author 星河一叶Ck
 * @date 2025/5/28
 */

@Tag(name = "站点管理")
@RestController
@RequestMapping("/station")
@RequiredArgsConstructor
public class StationController extends BaseController {

    private final IStationService stationService;

    // 查询站点列表
    @Operation(summary = "查询站点列表")
    @GetMapping("/list")
    public TableDataInfo list (Station station) {
        startPage();
        List<Station> list = stationService.selectStationList(station);
        return getDataTable(list);
    }

    // 添加
    @Operation(summary = "添加站点")
    @PostMapping
    public AjaxResult add (@RequestBody Station station) {
        return toAjax(stationService.addStation(station));
    }

    // 修改
    @Operation(summary = "修改站点")
    @PutMapping
    public AjaxResult edit (@RequestBody Station station) {
        return toAjax(stationService.updateStation(station));
    }

    // 查看站点详细信息
    @Operation(summary = "查看站点详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo (@PathVariable("id") Long id) {
        return success(stationService.getById(id));
    }

    // 删除站点
    @Operation(summary = "删除站点")
    @DeleteMapping("/{ids}")
    private AjaxResult remove (@PathVariable Long[] ids) {
        return toAjax(stationService.removeByIds(Arrays.asList(ids)));
    }

    // 站点设置关联数据
    @Operation(summary = "站点设置关联数据")
    @PostMapping("/setData")
    public AjaxResult setData (@RequestBody Station station) {
        return toAjax(stationService.setData(station));
    }

    @Operation(summary = "更新初始化数据")
    @GetMapping("/updateData")
    public AjaxResult updateData () {
        stationService.updateData();
        return success();
    }

}
